#import "MSGOnSender.h"
#import "CallUserViewController.h"
#import "MsgLogic.h"
@implementation MSGOnSender
SINGLETON_FOR_CLASS(MSGOnSender)
-(void)OnSender:(VMsgMessage *)sender;
{
    switch (sender.type) {
        case ReceiveCall:
            [self receivCall:sender];
            break;
        case CallStateChange:
            [self callStateChange:sender];
            break;
        case CallStateEnd:
            [self callStateEnd:sender];
            break;
        case CY_CHAT_GIFT:
            break;
        case VideoProhibition:
            [self pushVideoProhibitionWith:sender.msg_content];
            break;
        default:
            break;
    }
}
-(void)pushVideoProhibitionWith:(NSString *)message
{
    NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:message,@"data", nil];
    NSNotification *notification =[NSNotification notificationWithName:KVideoProhibition object:nil userInfo:dict];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}
-(void)pushUnMessage:(NSString *)string {
    UnifiedMessage *message = [UnifiedMessage modelWithJSON:string];
    if(message.type == CY_CHAT_GIFT)
    {
        [self giftMessage:message];
    }
}
-(void)pushCallMessage:(VMsgMessage *)message Uid:(NSString *)uid
{
    NSData *data = [message modelToJSONData];
    TIMConversation * conversation = [[TIMManager sharedInstance] getConversation:TIM_C2C receiver:uid];
    TIMCustomElem * jsondata = [[TIMCustomElem alloc] init];
    jsondata.data = data;
    TIMMessage * msg = [[TIMMessage alloc] init];
    [msg addElem:jsondata];
    [conversation sendMessage:msg succ:^{
    } fail:^(int code, NSString *msg) {
        [MBProgressHUD showTopTipMessage:msg];
    }];
}
- (void) giftMessage:(UnifiedMessage *)model{
    NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:model,@"data", nil];
    NSNotification *notification =[NSNotification notificationWithName:KOnGiftMessage object:nil userInfo:dict];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}
-(void)receivCall:(VMsgMessage *)model
{
    CallUserViewController *call = [CallUserViewController new];
    call.msessage = model;
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:call];
    [[kAppDelegate getCurrentVC] presentViewController:nav animated:NO completion:nil];
}
-(void)callStateEnd:(VMsgMessage *)model
{
    NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:model,@"data", nil];
    NSNotification *notification =[NSNotification notificationWithName:KOnCallEnd object:nil userInfo:dict];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}
-(void)callStateChange:(VMsgMessage *)model
{
    NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:model,@"data", nil];
    NSNotification *notification =[NSNotification notificationWithName:KOnCallConnecting object:nil userInfo:dict];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}
@end
